﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentValidation.Validators;

namespace NursingHome.Model.Validators.CustomValidators
{
    public class DateValidator: PropertyValidator
    {
        public DateValidator() : base("{PropertyName} is not a valid date.")
        {            
        }

        protected override bool IsValid(PropertyValidatorContext context)
        {
            var dateString = context.PropertyValue as string;
            if (String.IsNullOrWhiteSpace(dateString) == false)
            {
                DateTime date;
                return DateTime.TryParse(dateString, out date);
            }
            return true;
        }
    }
}
